package com.lhl.jwt.token;

import com.nimbusds.jwt.SignedJWT;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;

public class JwtAuthenticationToken extends AbstractAuthenticationToken {
	
	private static final long serialVersionUID = 1L;

	private UserDetails principal;
	
	private String credentials;
	
	private SignedJWT token;
	
	public JwtAuthenticationToken(SignedJWT token) {
		super(Collections.emptyList());
		this.token = token;
	}
	
	public JwtAuthenticationToken(UserDetails principal, SignedJWT token, Collection<? extends GrantedAuthority> authorities) {
		super(authorities);
		this.principal = principal;
		this.token = token;
	}
	
	@Override
	public void setDetails(Object details) {
		super.setDetails(details);
		this.setAuthenticated(true);
	}

	@Override
	public String getCredentials() {
		return credentials;
	}

	@Override
	public Object getPrincipal() {
		return principal;
	}
	
	public SignedJWT getToken() {
		return token;
	}
	
}
